<?php

/**
 * CreateMarketplaceItemLabelsRequest.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for FBA inbound operations.
 *
 * The Selling Partner API for Fulfillment By Amazon (FBA) Inbound. The FBA Inbound API enables building inbound workflows to create, manage, and send shipments into Amazon's fulfillment network. The API has interoperability with the Send-to-Amazon user interface.
 *
 * The version of the OpenAPI document: 2024-03-20
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\fulfillment\inbound\v2024_03_20;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * CreateMarketplaceItemLabelsRequest Class Doc Comment.
 *
 * @category Class
 *
 * @description The &#x60;createMarketplaceItemLabels&#x60; request.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class CreateMarketplaceItemLabelsRequest implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'CreateMarketplaceItemLabelsRequest';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'height' => 'float',
        'label_type' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\LabelPrintType',
        'locale_code' => 'string',
        'marketplace_id' => 'string',
        'msku_quantities' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\MskuQuantity[]',
        'page_type' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\ItemLabelPageType',
        'width' => 'float'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'height' => null,
        'label_type' => null,
        'locale_code' => null,
        'marketplace_id' => null,
        'msku_quantities' => null,
        'page_type' => null,
        'width' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'height' => true,
        'label_type' => false,
        'locale_code' => true,
        'marketplace_id' => false,
        'msku_quantities' => false,
        'page_type' => true,
        'width' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'height' => 'height',
        'label_type' => 'labelType',
        'locale_code' => 'localeCode',
        'marketplace_id' => 'marketplaceId',
        'msku_quantities' => 'mskuQuantities',
        'page_type' => 'pageType',
        'width' => 'width',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'height' => 'setHeight',
        'label_type' => 'setLabelType',
        'locale_code' => 'setLocaleCode',
        'marketplace_id' => 'setMarketplaceId',
        'msku_quantities' => 'setMskuQuantities',
        'page_type' => 'setPageType',
        'width' => 'setWidth',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'height' => 'getHeight',
        'label_type' => 'getLabelType',
        'locale_code' => 'getLocaleCode',
        'marketplace_id' => 'getMarketplaceId',
        'msku_quantities' => 'getMskuQuantities',
        'page_type' => 'getPageType',
        'width' => 'getWidth',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('height', $data ?? [], null);
        $this->setIfExists('label_type', $data ?? [], null);
        $this->setIfExists('locale_code', $data ?? [], 'en_US');
        $this->setIfExists('marketplace_id', $data ?? [], null);
        $this->setIfExists('msku_quantities', $data ?? [], null);
        $this->setIfExists('page_type', $data ?? [], null);
        $this->setIfExists('width', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (!is_null($this->container['height']) && ($this->container['height'] > 1E+2)) {
            $invalidProperties[] = "invalid value for 'height', must be smaller than or equal to 1E+2.";
        }

        if (!is_null($this->container['height']) && ($this->container['height'] < 25)) {
            $invalidProperties[] = "invalid value for 'height', must be bigger than or equal to 25.";
        }

        if (null === $this->container['label_type']) {
            $invalidProperties[] = "'label_type' can't be null";
        }
        if (!is_null($this->container['locale_code']) && !preg_match('/^[a-z]{2}_[A-Z]{2}$/', $this->container['locale_code'])) {
            $invalidProperties[] = "invalid value for 'locale_code', must be conform to the pattern /^[a-z]{2}_[A-Z]{2}$/.";
        }

        if (null === $this->container['marketplace_id']) {
            $invalidProperties[] = "'marketplace_id' can't be null";
        }
        if (mb_strlen($this->container['marketplace_id']) > 20) {
            $invalidProperties[] = "invalid value for 'marketplace_id', the character length must be smaller than or equal to 20.";
        }

        if (mb_strlen($this->container['marketplace_id']) < 1) {
            $invalidProperties[] = "invalid value for 'marketplace_id', the character length must be bigger than or equal to 1.";
        }

        if (null === $this->container['msku_quantities']) {
            $invalidProperties[] = "'msku_quantities' can't be null";
        }
        if (count($this->container['msku_quantities']) > 100) {
            $invalidProperties[] = "invalid value for 'msku_quantities', number of items must be less than or equal to 100.";
        }

        if (count($this->container['msku_quantities']) < 1) {
            $invalidProperties[] = "invalid value for 'msku_quantities', number of items must be greater than or equal to 1.";
        }

        if (!is_null($this->container['width']) && ($this->container['width'] > 1E+2)) {
            $invalidProperties[] = "invalid value for 'width', must be smaller than or equal to 1E+2.";
        }

        if (!is_null($this->container['width']) && ($this->container['width'] < 25)) {
            $invalidProperties[] = "invalid value for 'width', must be bigger than or equal to 25.";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets height.
     */
    public function getHeight(): ?float
    {
        return $this->container['height'];
    }

    /**
     * Sets height.
     *
     * @param null|float $height the height of the item label
     */
    public function setHeight(?float $height): self
    {
        if (is_null($height)) {
            array_push($this->openAPINullablesSetToNull, 'height');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('height', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($height) && ($height > 1E+2)) {
            throw new \InvalidArgumentException('invalid value for $height when calling CreateMarketplaceItemLabelsRequest., must be smaller than or equal to 1E+2.');
        }
        if (!is_null($height) && ($height < 25)) {
            throw new \InvalidArgumentException('invalid value for $height when calling CreateMarketplaceItemLabelsRequest., must be bigger than or equal to 25.');
        }

        $this->container['height'] = $height;

        return $this;
    }

    /**
     * Gets label_type.
     */
    public function getLabelType(): string
    {
        return $this->container['label_type'];
    }

    /**
     * Sets label_type.
     *
     * @param string $label_type label_type
     */
    public function setLabelType(string $label_type): self
    {
        if (is_null($label_type)) {
            throw new \InvalidArgumentException('non-nullable label_type cannot be null');
        }
        $this->container['label_type'] = $label_type;

        return $this;
    }

    /**
     * Gets locale_code.
     */
    public function getLocaleCode(): ?string
    {
        return $this->container['locale_code'];
    }

    /**
     * Sets locale_code.
     *
     * @param null|string $locale_code the locale code constructed from ISO 639 language code and ISO 3166-1 alpha-2 standard of country codes separated by an underscore character
     */
    public function setLocaleCode(?string $locale_code): self
    {
        if (is_null($locale_code)) {
            array_push($this->openAPINullablesSetToNull, 'locale_code');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('locale_code', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($locale_code) && (!preg_match('/^[a-z]{2}_[A-Z]{2}$/', ObjectSerializer::toString($locale_code)))) {
            throw new \InvalidArgumentException('invalid value for $locale_code when calling CreateMarketplaceItemLabelsRequest., must conform to the pattern /^[a-z]{2}_[A-Z]{2}$/.');
        }

        $this->container['locale_code'] = $locale_code;

        return $this;
    }

    /**
     * Gets marketplace_id.
     */
    public function getMarketplaceId(): string
    {
        return $this->container['marketplace_id'];
    }

    /**
     * Sets marketplace_id.
     *
     * @param string $marketplace_id The Marketplace ID. For a list of possible values, refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids).
     */
    public function setMarketplaceId(string $marketplace_id): self
    {
        if (is_null($marketplace_id)) {
            throw new \InvalidArgumentException('non-nullable marketplace_id cannot be null');
        }
        if (mb_strlen($marketplace_id) > 20) {
            throw new \InvalidArgumentException('invalid length for $marketplace_id when calling CreateMarketplaceItemLabelsRequest., must be smaller than or equal to 20.');
        }
        if (mb_strlen($marketplace_id) < 1) {
            throw new \InvalidArgumentException('invalid length for $marketplace_id when calling CreateMarketplaceItemLabelsRequest., must be bigger than or equal to 1.');
        }

        $this->container['marketplace_id'] = $marketplace_id;

        return $this;
    }

    /**
     * Gets msku_quantities.
     */
    public function getMskuQuantities(): array
    {
        return $this->container['msku_quantities'];
    }

    /**
     * Sets msku_quantities.
     *
     * @param array $msku_quantities represents the quantity of an MSKU to print item labels for
     */
    public function setMskuQuantities(array $msku_quantities): self
    {
        if (is_null($msku_quantities)) {
            throw new \InvalidArgumentException('non-nullable msku_quantities cannot be null');
        }

        if (count($msku_quantities) > 100) {
            throw new \InvalidArgumentException('invalid value for $msku_quantities when calling CreateMarketplaceItemLabelsRequest., number of items must be less than or equal to 100.');
        }
        if (count($msku_quantities) < 1) {
            throw new \InvalidArgumentException('invalid length for $msku_quantities when calling CreateMarketplaceItemLabelsRequest., number of items must be greater than or equal to 1.');
        }
        $this->container['msku_quantities'] = $msku_quantities;

        return $this;
    }

    /**
     * Gets page_type.
     */
    public function getPageType(): ?string
    {
        return $this->container['page_type'];
    }

    /**
     * Sets page_type.
     *
     * @param null|string $page_type page_type
     */
    public function setPageType(?string $page_type): self
    {
        if (is_null($page_type)) {
            array_push($this->openAPINullablesSetToNull, 'page_type');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('page_type', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['page_type'] = $page_type;

        return $this;
    }

    /**
     * Gets width.
     */
    public function getWidth(): ?float
    {
        return $this->container['width'];
    }

    /**
     * Sets width.
     *
     * @param null|float $width the width of the item label
     */
    public function setWidth(?float $width): self
    {
        if (is_null($width)) {
            array_push($this->openAPINullablesSetToNull, 'width');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('width', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($width) && ($width > 1E+2)) {
            throw new \InvalidArgumentException('invalid value for $width when calling CreateMarketplaceItemLabelsRequest., must be smaller than or equal to 1E+2.');
        }
        if (!is_null($width) && ($width < 25)) {
            throw new \InvalidArgumentException('invalid value for $width when calling CreateMarketplaceItemLabelsRequest., must be bigger than or equal to 25.');
        }

        $this->container['width'] = $width;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
